package innerclassAndLambda;

/**
 * @author feng
 * @Date 2021/7/19 15:45
 * 设置标记位，让线程停止
 */
public class StopThread implements Runnable {
    private boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while (flag) {
            System.out.println("线程正在运行" + i++);
        }
    }

    public void stop() {
        this.flag = false;
    }

    public static void main(String[] args) {
        StopThread thread = new StopThread();
        new Thread(thread).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("main" + i);
            if (i == 900) {
                thread.stop();
                System.out.println("线程停止运行....."+i);
            }
        }

    }


}
